package ro.flashbite.console
{
	import ro.flashbite.interfaces.IDestroyable;
	
	import flash.events.Event;
	
	/**
	 * Event dispached by console when some of his buttons are pressed (sleep, wakeup, destroy, close, level list combo, binding buttons)
	 * 
	 * v 1.0
	 * 
	 * @author Adrian Barbu
	 */
	public final class ConsoleEvent extends Event implements IDestroyable
	{
		/**
		 * event names speak themselves
		 */		
		public static const		SLEEP				:	String 	= "ConsoleEvent_Sleep";
		public static const		WAKEUP				:	String 	= "ConsoleEvent_Wakeup";
		public static const		DESTROY				:	String 	= "ConsoleEvent_Destroy";
		
		public static const		CONSOLE_CLOSE		:	String 	= "ConsoleEvent_ExitBtn_Click";
		
		public static const		BINDING_CLICK		:	String 	= "ConsoleEvent_Binding_Click";
		
		public static const		COMBO_LEVEL_CLICK	:	String 	= "ConsoleEvent_ComboLevel_Click";
		
		/**
		 * data to send from console to listeners; Almost all the time data will be String type
		 */		
		private var _data	:	Object;
		
		// ================================================================================================================================
		// CONSTRUCTOR
		// ================================================================================================================================
		
		public function ConsoleEvent(type:String, data:Object = null)
		{
			super(type);
			
			_data = data;
		}
		
		// ================================================================================================================================
		// DESTRUCTOR
		// ================================================================================================================================
		
		public function destroy():void
		{
			if (_data) {
				if (_data is IDestroyable) {
					(_data as IDestroyable).destroy();
				}
				
				_data = null;
			}
		}
		
		// ================================================================================================================================
		// PUBLIC
		// ================================================================================================================================
		
		override public function clone():Event { return new ConsoleEvent(type, _data); }
		
		override public function toString():String 
		{ 
			return "[ConsoleEvent type=" + type + " data=" + _data + " bubbles=" + bubbles + "cancelable=" + cancelable + " eventPhase=" + eventPhase + "]"; 
		}
		
		// ================================================================================================================================
		// GETTERS
		// ================================================================================================================================
		
		public function get data():Object { return _data; }
	}
}